#include "../Base/stdafx.h"
#include "../xml/XmlLoader.h"
#include "Animation.h"
#include "../Base/StringUtil.h"


Animation::Animation( const tstring& file )
{
	XMLLoader xmlFile(file);
	int id = -1;
	vector<D3DXVECTOR3> rots;
	do 
	{
		if(xmlFile.GetStartElement() == _T("bone"))
		{
			if(id != -1)
			{
				m_Anim.insert(make_pair(id, rots));
				rots.clear();
			}
			id = StringUtil::ToInt(xmlFile.GetValue(_T("id")));
		}else if(xmlFile.GetStartElement() == _T("rotation")) {
			float rx = StringUtil::ToFloat(xmlFile.GetValue(_T("rx")));
			float ry = StringUtil::ToFloat(xmlFile.GetValue(_T("ry")));
			float rz = StringUtil::ToFloat(xmlFile.GetValue(_T("rz")));
			rots.push_back(D3DXVECTOR3(rx, ry, rz));
		}
	} while (xmlFile.Next());
	m_Anim.insert(make_pair(id, rots));
}

Animation::~Animation()
{

}

const vector<D3DXVECTOR3>& Animation::GetAnim( int id ) const
{
	return m_Anim.find(id)->second;
}